﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using Quanlybanhang_pro202.Control;

namespace Quanlybanhang_pro202.View
{
    public partial class FrmLogin : Form
    {
        public FrmLogin()
        {
            InitializeComponent();
        }

        private void FrmLogin_Load(object sender, EventArgs e)
        {
            
        }

        private void BtnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                Taikhoan_Control tk = new Taikhoan_Control();
                DataTable dt = new DataTable();
                dt = tk.Login(txtUser.Text, txtPass.Text).Tables["login"];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        switch (dt.Rows[i].ItemArray[3].ToString())
                        {
                            case "1":
                                FrmAdmin ad = new FrmAdmin();
                                ad.Show();
                                this.Hide();
                                break;
                            case "2":
                                FrmThungan tn = new FrmThungan();
                                tn.Show();
                                this.Hide();
                                break;
                            default:
                                MessageBox.Show("Your account have been locked!");
                                break;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Invalid Username or Password! Please try again");
                }
            }
            catch
            {
                MessageBox.Show("Invalid input information! Please try again");
            }
        }
        
    }
}
